package cc.magicjson.example.demo;

import java.util.Random;

public class MontyHallProblemValidator {
    private static final int SIMULATIONS = 1000000;
    private static final Random RANDOM = new Random();

    public static void main(String[] args) {
        int winsByNotSwitching = 0;
        int winsBySwitching = 0;
        for (int i = 0; i < SIMULATIONS; i++) {
            // 随机选择一扇门放置奖品
            int prizeDoor = RANDOM.nextInt(3);
            // 参赛者随机选择一扇门
            int participantChoice = RANDOM.nextInt(3);
            // 如果参赛者选择正确
            if (participantChoice == prizeDoor) {
                winsByNotSwitching++; // 不换门则赢
            } else {
                winsBySwitching++; // 换门则赢，因为主持人已经排除了一扇山羊的门
            }
        }
        // 输出概率
        System.out.println("不换门获奖的概率: " + ((double) winsByNotSwitching / SIMULATIONS));
        System.out.println("换门获奖的概率: " + ((double) winsBySwitching / SIMULATIONS));
    }
}
